<?php

declare(strict_types=1);

namespace App\Cola\Model;

use Hyperf\Database\Model\SoftDeletes;
use Mine\MineModel;

/**
 * @property int $id ID
 * @property int $group_id 组别ID
 * @property string $nickname 昵称
 * @property string $password 密码
 * @property int $status 状态:1=正常,0=冻结
 * @property string $email 电子邮箱
 * @property string $mobile 手机号
 * @property string $avatar 头像
 * @property int $gender 性别
 * @property string $birthday 生日
 * @property string $signed 格言
 * @property int $successions 连续登录天数
 * @property int $max_successions 最大连续登录天数
 * @property int $login_failure 失败次数
 * @property string $prev_time 上次登录时间
 * @property string $login_time 登录时间
 * @property string $login_ip 登录IP
 * @property string $join_ip 加入IP
 * @property string $join_time 加入时间
 * @property \Carbon\Carbon $created_at 创建时间
 * @property \Carbon\Carbon $updated_at 更新时间
 * @property string $deleted_at 删除时间
 */
class ColaUser extends MineModel
{
    use SoftDeletes;
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'cola_user';


    protected array $fillable = ['group_id', 'nickname', 'password', 'status', 'gender', 'email', 'mobile', 'avatar', 'birthday', 'signed', 'login_ip', 'login_time', 'prev_time', 'join_time', 'join_ip'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = [
        'id' => 'integer',
        'group_id' => 'integer',
        'status' => 'integer',
        'gender' => 'integer',
        'successions' => 'integer',
        'max_successions' => 'integer',
        'login_failure' => 'integer',
        'login_ip' => 'integer',
        'join_ip' => 'integer',
        'login_time' => 'datetime',
        'prev_time' => 'datetime',
        'join_time' => 'datetime'
    ];

    /**
     * 密码加密.
     * @param mixed $value
     */
    public function setPasswordAttribute(mixed $value): void
    {
        var_dump($value);
        $this->attributes['password'] = password_hash($value, PASSWORD_DEFAULT);
    }

    /**
     * 验证密码
     * @param mixed $password
     * @param mixed $hash
     */
    public static function passwordVerify($password, $hash): bool
    {
        return password_verify($password, $hash);
    }
}
